package com.kdtech.analyse.outside;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * 英文虎报
 * @author Persh
 *
 */
public class ThestandardNewsAnalyse implements AnalyseNews {
	
	private static final String[] regex={
		"http://www.thestandard.com.hk/breaking_news_detail.asp\\?id=[0-9]*",
		"http://www.thestandard.com.hk/news_detail.asp\\?art_id=[0-9]*.*"
	};
	
	
	
	public boolean isDetailPage(String url) {
		for (int i=0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return false;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		NewsMeta news=new NewsMeta();
		if (urlMeta.getHtml() == null) {
		}		
		String htmltxt=urlMeta.getHtml();
		String url=urlMeta.getUrl();		
				
		news.setUrl(url);		
		String title=null;
		String content=null;
		String author=null;
		Long date=null;
		Document doc=Jsoup.parse(htmltxt);
		title =doc.select("span.bodyHeadline").text();
		if(StringUtils.isBlank(title)){
			title=doc.select("b.bodyHeadline").text();
		}
		content=HtmlCleaner.getContentHtml(url,doc.select("span.bodyCopy"));
		date=DateUtils.matchDate(doc.select("span.bodyCopy i").text());

		if(StringUtils.isBlank(title)){
		}
		news.setTitle(StringUtils.trimSpace(title));
		news.setContent(content);
		news.setAuthor(author);
		news.setDate(date);	
		
		return news;
	}
	
	

	

	
}
